﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GridReport
{
    /// <summary>
    /// YDReport 的摘要说明
    /// </summary>
    public class YDReport : IHttpHandler
    {
        /// <summary>
        /// 报表访问接口
        /// 参数规范：
        /// 1.所有参数转为json赋值给data
        /// 2.访问地址+"?data=json"
        /// 3.json 中包含访问的报表如 
        /// {
        ///     report："tjbb"， //报表名称标识
        ///           
        ///     v_tjbh:"018164", //参数
        ///     v_tjcs:"1"
        ///     
        /// } 
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.QueryString["data"] != "")
            {
                var data = context.Request.QueryString["data"];
                JObject jo= JsonConvert.DeserializeObject<JObject>(data);
                var url = "http://www.hk99.com/YDReport/";
                if (jo.GetValue("report") != null)
                {
                    var html = jo["report"].ToString().Trim() + ".html";
                }
                jo.Remove("report");

                var par = "";
                int num = 0;
                foreach (var item in jo)
                {
                    if (num == 0)
                    {
                        par += "?" + item.Key + "=" + item.Value;
                    }
                    else
                    {
                        par += "&"+item.Key + "=" + item.Value;
                    }
                    num++;
                }

            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}